package yyds.sniarbtej;

import yyds.sniarbtej.transformer.util.IntellijMethodUtil;

import java.io.File;
import java.lang.instrument.Instrumentation;

public final class Environment {
    private final String version;
    private final String appName;
    private final File baseDir;
    private final File agentFile;
    private final boolean attachMode;
    private final Instrumentation instrumentation;

    public Environment(Instrumentation instrumentation, File agentFile, String appName, boolean attachMode) {
        this.instrumentation = instrumentation;
        this.agentFile = agentFile;
        this.baseDir = agentFile.getParentFile();
        if (appName == null || appName.isEmpty()) {
            this.appName = "";
        } else {
            this.appName = appName.toLowerCase();
        }

        this.version = "2024.2.4";
        this.attachMode = attachMode;
        IntellijMethodUtil.setEnvironment(this);
    }

    private String getVersion() {
        return this.version;
    }

    private String getAppName() {
        return this.appName;
    }

    private File getBaseDir() {
        return this.baseDir;
    }

    public final File getAgentFile() {
        return this.agentFile;
    }

    public boolean isAttachMode() {
        return this.attachMode;
    }

    public Instrumentation getInstrumentation() {
        return this.instrumentation;
    }

    public String toString() {
        return "Environment: {\n\tversion = " + this.version + ", \n\tappName = " + this.appName + ", \n\tbaseDir = " + this.baseDir + ", \n\tagentFile = " + this.agentFile + ", \n\tattachMode = " + this.attachMode + "\n}";
    }
}
